#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:pengfeifu
@file: db_config.py.py 
@version:
@time: 2021/11/09 
@email:1324734112@qq.com
@desc： 
@function：常用函数
"""

import os
import configparser

global config_name
config_name = "db_mysql_config.cnf"


class Config(object):
    def __init__(self):
        config_file_path = os.path.join(os.path.dirname(__file__), config_name)
        self.cf = configparser.ConfigParser()
        self.cf.read(config_file_path)

    def get_option(self, section):
        option_list = self.cf.options(section)
        return option_list

    def get_config_content(self, section):
        option_list = self.get_option(section)
        config_content = {}
        for option in option_list:
            value = self.cf.get(section, option)
            config_content[option] = int(value) if value.isdigit() else value
        return config_content


if __name__ == "__main__":
    content_dict = Config().get_config_content("db_mysql_aliyun")
    for option in content_dict:
        print(f"key:{option},value:{content_dict.get(option)}")
